


from PyQt5.QtWidgets import QDialogButtonBox,QColorDialog,QWidget,QLabel,\
QSlider,QGroupBox,QVBoxLayout
from PyQt5.QtGui import QFont
from PyQt5.QtCore import Qt
from mylibs.shape import Shape
BB = QDialogButtonBox

class ColorDialog(QColorDialog):

    def __init__(self, parent=None):
        super(ColorDialog, self).__init__(parent)
        self.setOption(QColorDialog.ShowAlphaChannel)
        self.setOption(QColorDialog.DontUseNativeDialog)

        self.default = None
        self.bb = self.layout().itemAt(1).widget()

        self.bb.addButton(BB.RestoreDefaults)
        self.bb.clicked.connect(self.checkRestore)

    def getColor(self, value=None, title=None, default=None):
        self.default = default
        if title:
            self.setWindowTitle(title)
        if value:
            self.setCurrentColor(value)
        return self.currentColor() if self.exec_() else None

    def checkRestore(self, button):
        if self.bb.buttonRole(button) & BB.ResetRole and self.default:
            self.setCurrentColor(self.default)

class MainWindow_slider(QWidget):
    def __init__(self):
        super(MainWindow_slider,self).__init__()
        self.width = 400
        self.height = 350
        # 设置固定尺寸
        self.setFixedSize(self.width, self.height)
        self.projectListShowed = False
        self.Pro_task = ''
        self.savePath = ''
        self.canvas = None

        self.setWindowTitle('调整线条粗细')
        self.lb1 = QLabel('标注框粗细')
        self.lb1.setAlignment(Qt.AlignCenter)
        self.lb2 = QLabel('标签大小')
        self.lb2.setAlignment(Qt.AlignCenter)
        #----------------
        self.slider1 = QSlider(Qt.Horizontal)#水平方向
        self.slider1.setMinimum(1)#设置最小值
        self.slider1.setMaximum(10)#设置最大值
        self.slider1.setSingleStep(1)#设置步长值
        self.slider1.setValue(3)#设置当前值
        self.slider1.setTickPosition(QSlider.TicksBelow)#设置刻度位置，在下方
        self.slider1.setTickInterval(1)#设置刻度间隔
        self.slider1.valueChanged.connect(self.valueChange)
        #----------------
        self.slider2 = QSlider(Qt.Horizontal)#水平方向
        self.slider2.setMinimum(2)#设置最小值
        self.slider2.setMaximum(50)#设置最大值
        self.slider2.setSingleStep(1)#设置步长值
        self.slider2.setValue(20)#设置当前值
        # self.s.setTickPosition(QSlider.TicksBelow)#设置刻度位置，在下方
        self.slider2.setTickInterval(1)#设置刻度间隔
        self.slider2.valueChanged.connect(self.valueChange2)
        #----------------
        self.group1 = QGroupBox('调整线条粗细')
        self.group2 = QGroupBox('调整标签大小')
        layout = QVBoxLayout(self.group1)
        layout2 = QVBoxLayout(self.group2)
        layout.addWidget(self.lb1)
        layout.addWidget(self.slider1)
        layout2.addWidget(self.lb2)
        layout2.addWidget(self.slider2)
        self.layout_all = QVBoxLayout(self)
        self.layout_all.addWidget(self.group1)
        self.layout_all.addWidget(self.group2)

    def valueChange(self):
        Shape.line_thick = self.slider1.value()
        self.canvas.update()
        size = self.slider1.value()
        self.lb1.setFont(QFont("Arial",size))

    def valueChange2(self):
        print(self.slider2.value())
        Shape.label_thick =  self.slider2.value()
        self.canvas.update()
        size = self.slider2.value()
        self.lb2.setFont(QFont("Arial", size))